package com.ruoyi.personnel.salary.piece.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.personnel.salary.piece.domain.PieceCond;
import com.ruoyi.personnel.salary.piece.domain.PieceDomain;
import com.ruoyi.personnel.salary.piece.domain.PieceDto;
import com.ruoyi.personnel.salary.piece.service.IPieceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 计件工资
 * 视图层
 */
@RestController
@RequestMapping("/salary/piece")
@Api(value = "计件工资信息模块", tags = "计件工资接口")
public class PieceController extends BaseController {
    @Autowired
    private IPieceService pieceService;

    /**
     * 根据搜索条件所有计件工资记录
     * @param cond 搜索条件
     * @return
     */
    @ApiOperationSupport(includeParameters = {"PieceCond.pieceRateId", "PieceCond.staffId", "PieceCond.receivingReportId", "PieceCond.createTime"})
    @ApiOperation(value = "获取计件工资列表",notes = "查询所有计件工资信息")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody PieceCond cond) {
        startPage();
        List<PieceDto> pieceDtos = pieceService.selectPieceList(cond);
        return getDataTable(pieceDtos);
    }

    /**
     * 新增计件工资记录
     * @param piece
     * @return
     */
    @ApiOperation(value = "新增计件工资记录", notes = "新增计件工资记录信息")
    @ApiImplicitParam(name = "piece", value = "新增计件工资记录", dataType = "PieceDomain")
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody PieceDomain piece) {
        return toAjax(pieceService.insertPiece(piece));
    }

    /**
     * 修改计件工资记录
     * @param piece
     * @return
     */
    @ApiOperation(value = "修改计件工资记录", notes = "修改计件工资信息")
    @ApiImplicitParam(name = "piece", value = "修改计件工资记录", dataType = "PieceDomain")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody PieceDomain piece) {
        return toAjax(pieceService.updatePiece(piece));
    }

    /**
     * 删除计件工资记录
     * 仅修改删除标志
     * @param piece
     * @return
     */
    @ApiOperation(value = "删除计件工资记录", notes = "删除计件工资记录,仅删除标志位")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody PieceDomain piece) {
        return toAjax(pieceService.updatePieceDeleteFlag(piece));
    }
}
